#ifndef SOAREQUEST_H
#define SOAREQUEST_H
#include <QHttp>
#include "QmyDom.h"
#include "webserviceconfig.h"
#include <QThread>
#include "FileFunction.h"

typedef enum
{  
  NOT_FOUND = 404,
  STREAM_PNG, /* image 1 png */
  STREAM_JPG,    /* image 2 jpg */
  STREAM_GIF,  /* image 3 gif */
  STREAM_TXT, /* normal text */
  STREAM_BIN      /* binary format zip or other */
} DATATYPE;

Q_DECLARE_METATYPE(DATATYPE);

class LoadSoa : public QHttp
{
    Q_OBJECT
//
public: 
     LoadSoa( int nr , QUrl url_send , QDomDocument send_doc );
     void Start();
     inline int Get_id() { return cid; }
     inline int Htpp_id() { return Http_id; }  
     inline QDomDocument Doc() { return doc; }  
     inline QDomDocument HDoc() { return hdoc; }  
    QDomDocument doc;
    QDomDocument hdoc;
    int cid;
    int Http_id;
    QHttpRequestHeader header;
    QUrl url;
    QBuffer *buffer_send;
    signals:
      void take(int,int);
    public slots:
     void PageReady( bool error );
};


class LoadGet : public QHttp
{
    Q_OBJECT
//
public: 
     LoadGet( int nr , QUrl url_send  , DATATYPE e = STREAM_BIN );
     void Start();
     inline int Get_id() { return cid; }
     inline int Htpp_id() { return Http_id; } 
     inline QPixmap pics() { return resultimage; } 
    int cid;
    int Http_id;
    DATATYPE wait_on;
    QHttpRequestHeader header;
    QUrl url;
    QPixmap resultimage;
    signals:
      void take(int);
    public slots:
     void ImageReady( bool error );
};



class RequestSoa : public QThread
{
    Q_OBJECT
     
public:
  void Setting( QObject *parent , int id , QUrl url_send ,  QDomDocument send_doc ); 
protected:
  void run();
  signals:
private:
    int cid;
    QUrl url;
    QDomDocument doc;
    LoadSoa *Rhttp;
    QObject* receiver;
}; 

class RequestStreams : public QThread
{
    Q_OBJECT
     
public:
  void Setting( QObject *parent , int id , QUrl url_send ,  DATATYPE e = STREAM_BIN ); 
protected:
  void run();
  signals:
private:
    int cid;
    QUrl url;
    DATATYPE must;
    LoadGet *Rhttp;
    QObject* receiver;
}; 






class SoaRequest : public QObject
{
     Q_OBJECT
//
public:
SoaRequest( QObject * parent = 0 );
void Login();
void Logout();
void Send( QString streams , QUrl url , const int memid = 404 );
void ListaCase( int tipo = 2 );
QDomDocument Casa_Doc( const int ipid );
inline int lastid() { return currentID; }
inline QString data() { return pIN; }
inline QDomDocument Doc_Current() { 
    
    QDomElement root = doc.documentElement();  
    root.setAttribute ("oggettotipo",Tipovigore);
    return doc; 
    
    }
protected:
    QSettings setter;
    int Tipovigore;
    bool Save_append_Session();
    QBuffer *buffer_send;
    QBuffer *buffer_incomming;
   QDomDocument doc;
   QHttp *ShttpR;
   int headercode;
   QHttpRequestHeader header;
   QString pIN;
   QUrl currenturl;
   int currentID;
   int current_HTTP_ID;
   void SetSessionId( QString streams );
   QMap<QString,QString> HeaderIncome;
QString WebSessionCurrent;
private:
    void ResetSession();
signals:
    void SendError();
    void SessionStatus(bool);
    void LastDone(int);
public slots:
   void Exitdone( bool e  );
   void ReciverStatus( int fatto , int tot );
   void SaveData(const QHttpResponseHeader &responseHeader );
   void SnState( const int state );


};
//
#endif // SOAREQUEST_H

